<%@ page import="com.tzy.newbank.Pojo.Bankuser" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<%
    String one= (String) session.getAttribute("money");
    Bankuser user = (Bankuser) session.getAttribute("user");
    String name="无";
    if (user != null) {
        name= user.getName();
    }
    session.setAttribute("user",user);
%>
<head>
    <script>
        // 当页面加载完成后，执行此函数
        window.onload = function() {
            // 从Local Storage中获取JWT令牌
            var jwtToken = localStorage.getItem('jwt');
            // alert('JWT令牌：'+jwtToken);

            // 将JWT令牌设置到隐藏域中
            document.getElementById('jwtToken4').value = jwtToken;
            document.getElementById('jwtToken5').value = jwtToken;
            document.getElementById('jwtToken6').value = jwtToken;
        };
    </script>
    <meta charset="UTF-8">
    <title>用户管理系统</title>
    <style>

        table {
            width: 80%;
            margin: 20px auto;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        .button-container {
            margin: 20px auto;
            text-align: center;
        }

        .button-container button {
            padding: 10px;
            margin: 0 10px;
            font-size: 16px;
            cursor: pointer;
        }

        /* 所有表单的通用样式 */
       #getForm,#freezeForm,#unfreezeForm {
            display: none;
            border: 1px solid #ccc;
            padding: 20px;
            border-radius: 8px;
            background-color: #f8f8f8;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        /* 表单标签的通用样式 */
        #getForm label,#freezeForm label,#unfreezeForm label {
            display: block;
            margin-bottom: 8px;
        }

        /* 表单输入框的通用样式 */
        #getForm input, #freezeForm input,#unfreezeForm input{
            width: 100%;
            padding: 8px;
            margin-bottom: 12px;
            box-sizing: border-box;
        }

        /* 表单按钮的通用样式 */
        #getForm button,#freezeForm button,#unfreezeForm button {
            padding: 8px;
            background-color: #4caf50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        /* 鼠标悬停时按钮的颜色变化 */
        #getForm button,#freezeForm button:hover,#unfreezeForm button:hover{
            background-color: #45a049;
        }
    </style>
    <script>
        function showForm(formName) {
            disableOtherElements(true, formName);
            document.getElementById(formName).style.display = "block";
        }

        function hideForm(formName) {
            disableOtherElements(false, formName);
            document.getElementById(formName).style.display = "none";
        }

        function disableOtherElements(disable) {
            var elements = document.getElementsByClassName("dont");
            for (var i = 0; i < elements.length; i++) {
                elements[i].disabled = disable;
            }
        }
    </script>
</head>
<body>
<h2>银行管理系统 - 欢迎管理员登录<br><br><br><br><br></h2>
<%-- 人员信息表格 --%>
<table>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>密码</th>
        <th>存款</th>
        <th>状态</th>
    </tr>

    <%-- 循环展示人员信息 --%>
    <%
        List<Bankuser> peoples = (List<Bankuser>) session.getAttribute("peoples");

        if (peoples != null && !peoples.isEmpty()) {
            for (Bankuser employee : peoples) {
    %>
    <%-- 循环展示银行人员信息，对应上面的人员信息表格的属性列--%>
    <tr>
        <td><%= employee.getId() %>
        </td>
        <td><%= employee.getName() %>
        </td>
        <td><%= employee.getPassword() %>
        </td>
        <td><%= employee.getBalance() %>
        </td>
        <td><%= employee.getState() %>
        </td>
    </tr>
    <%
        }
    } else {
    %>
    <tr>
        <td colspan="3">暂无信息</td>
    </tr>
    <%
        }
    %>
</table>

<%-- 按钮操作区域 --%>
<div class="button-container">
    <button class="dont" onclick="showForm('getForm')">获取用户</button>
    <button class="dont" onclick="showForm('freezeForm')">冻结账户</button>
    <button class="dont" onclick="showForm('unfreezeForm')">解冻账户</button>
    <button class="dont" onclick="location.href='index.jsp'">返回登录页面</button>
</div>
<div id="getForm">
    <form action="http://127.0.0.1:8082/update/getInfo" method="post">
        <input type="hidden" id="jwtToken4" name="jwtToken">
        <button type="submit">获取</button>
    </form>
</div>
<div id="freezeForm">
    <form action="http://127.0.0.1:8082/update/freeze" method="post">
        <input type="hidden" id="jwtToken5" name="jwtToken">
        <label>目标用户名</label>
        <input type="text" id="user3" name="user2" required><br>
        <button type="submit">确认冻结</button>
        <button type="button" onclick="hideForm('freezeForm')">返回</button>
    </form>
</div>
<div id="unfreezeForm">
    <form action="http://127.0.0.1:8082/update/unfreeze" method="post">
        <input type="hidden" id="jwtToken6" name="jwtToken">
        <label>目标用户名</label>
        <input type="text" id="user4" name="user2" required><br>
        <button type="submit">确认解冻</button>
        <button type="button" onclick="hideForm('unfreezeForm')">返回</button>
    </form>
</div>
</body>
</html>
